package gwtmodule1.client.gui.shop;

import gwtmodule1.client.gui.PageShop;
import gwtmodule1.client.gui.shared.CartTable;
import gwtmodule1.client.gui.utils.HSpacer;
import gwtmodule1.client.gui.utils.Title;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class PageShoppingCart extends VerticalPanel {

	public PageShoppingCart(PageShop shop) {
		super();
		add(new Title("Shopping Cart"));
		add(createTable());
		add(new HSpacer());
		setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		add(createAddGiftCard());
		add(new HSpacer());
		Button b = new Button("enter payment/shipping information");
		b.addClickListener(shop.getPageSwitch(shop.getPageDeliver()));
		add(b);
		// setCellHorizontalAlignment(b, HasHorizontalAlignment.ALIGN_RIGHT);
	}

	private Widget createAddGiftCard() {
		HorizontalPanel hp = new HorizontalPanel();
		hp.add(new HTML("Gift Card ID: "));
		hp.add(new TextBox());
		hp.add(new Button("Use Gift Card"));
		return hp;
	}

	private Widget createTable() {
		CartTable table = new CartTable();
		float total = 0;
		for (int i = 1; i < 5; i++) {
			total += table.addItem("Company" + i, "DVD Player " + i, (i + 30)
					* i, (i * 3 % 4) + 1);
		}
		table.setGiftcard(60);
		float tax = total * 0.055f;
		table.setTax(5.5, tax);
		table.setShipping(13.3f);
		table.setTotal(total - 60 + tax + 13.3f);
		return table;
	}

}